package com.mq.consumer.mq;

import com.alibaba.fastjson.JSONObject;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 竞拍订单服务监听
 * @author duzq
 * @date 2022-2-7 23:07:56
 */
@Component
public class AuctionOrderCustomerListener {

    private final String queueNamePrefix = "竞拍订单-";

    @Autowired
    private RabbitAdmin rabbitAdmin;

    @RabbitListener(queues = "竞拍订单死信队列-竞拍开始")
    public void begin(String message) {
        System.out.println("竞拍订单服务监听##开始##" + message);

        // 移除无效的队列
        JSONObject jsonObject = JSONObject.parseObject(message);
        rabbitAdmin.deleteQueue(queueNamePrefix + jsonObject.getString("id"));
    }

    @RabbitListener(queues = "竞拍订单死信队列-竞拍结束")
    public void end(String message) {
        System.out.println("竞拍订单服务监听##结束##" + message);

        // 移除无效的队列
        JSONObject jsonObject = JSONObject.parseObject(message);
        rabbitAdmin.deleteQueue(queueNamePrefix + jsonObject.getString("id"));
    }
}
